package com.zusmart.core.bean.support;

import java.lang.reflect.Method;

import com.zusmart.base.util.Assert;
import com.zusmart.core.bean.BeanDefinition;
import com.zusmart.core.bean.BeanDefinitionRegistry;
import com.zusmart.core.bean.BeanDefinitionResolver;
import com.zusmart.core.bean.BeanDefinitionType;
import com.zusmart.core.bean.BeanInstanceCreator;

public class BeanDefinitionForMethod extends AbstractBeanDefinition {

	private BeanDefinition parentBeanDefinition;
	private Method parentBeanMethod;

	public BeanDefinitionForMethod(BeanDefinitionResolver beanDefinitionResolver, BeanDefinitionRegistry beanDefinitionRegistry, BeanDefinition parentBeanDefinition, Method parentBeanMethod, String beanName, String beanScope) {
		super(beanDefinitionResolver, beanDefinitionRegistry, beanName, beanScope, parentBeanMethod.getReturnType());
		Assert.isNull(parentBeanDefinition, "parent bean definition must not be null");
		this.parentBeanDefinition = parentBeanDefinition;
		this.parentBeanMethod = parentBeanMethod;
	}

	@Override
	public BeanDefinitionType getBeanType() {
		return BeanDefinitionType.Method;
	}

	@Override
	protected BeanInstanceCreator createBeanInstanceCreator() {
		return new BeanInstanceCreatorForMethod(this);
	}

	public BeanDefinition getParentBeanDefinition() {
		return parentBeanDefinition;
	}

	public Method getParentBeanMethod() {
		return parentBeanMethod;
	}

}